# coding: utf-8

import json
import os
import uuid
from io import BytesIO

import time
from flask import request, make_response, Response
from fraMail.framail import FraMail

import QRcodeOper
from fralog.FraLog import getFileLog
from exceptions.fra_exception import FraException
from settings import *
from dbproxy.dbproxy import *
from PIL import Image
from globalsettings import CUR_MODE
if CUR_MODE == 'dev':
    from globalsettings_dev import *
else:
    from globalsettings_prod import *
log = getFileLog()


class HRAudituserdemo(object):
    """
    hr demo 用户账号开通模块
    """
    table_name = 't_user'

    def __init__(self):
        super(HRAudituserdemo, self).__init__()
        self.db_proxy = DBProxy(db=mongo)

    def query_invoice_all(self, user_id):
        log.debug('查询用户发票: %s' % (user_id))
        ret = self.db_proxy.page_query(table='invoices_collection', query={'user_id': user_id})
        log.debug('用户发票查询结束')

hrAudituserdemo = HRAudituserdemo()


@app.route('/hrdemo/query_invoice_all', methods=['GET', 'POST'])
@verify_token
def hrdemo_query_invoice_all():
    '''
    返回:ret集合 ,ret.data=[]
    :return:
    '''
    log.debug(' ')
    param = get_param(request)
    g_user_id, ret = check_token(param.get('token'))
    # if param.get('token') == 'jim':
    #     g_user_id = 'test01'
    if g_user_id is None:
        return ret
    return json.dumps(hrAudituserdemo.query_invoice_all(user_id=g_user_id))
